//
//  QueueDictionary.h
//  Portal
//
//  Created by JingXing Wu on 12-3-13.
//  Copyright (c) 2012年 GuangZhouXuanWu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "XMSKvPair.h"

@interface XMSQueueDictionary : NSObject <NSFastEnumeration,NSMutableCopying>

@property(nonatomic, readonly) NSMutableArray *arQueue;
@property(nonatomic, readonly) Class storeCls;

- (id)initWithStoreClass:(Class)cls;

- (NSUInteger)count;

- (void)replaceKey:(NSUInteger)nIndex Key:(id)key;

//-(void)ReplaceKey:(id)oldkey newkey:(id)newkey;

- (NSMutableArray *)allKeys;

- (NSMutableArray *)allValues;

- (void)removeAllObjects;

- (void)removeObjectsInRange:(NSRange)range;

- (void)removeObjects:(NSArray *)arObj;

- (void)removeObject:(XMSKvPair *)kv;

- (void)removeObjectAtIndex:(NSUInteger)nIndex;

- (void)removeObjectForKey:(id)key;

- (void)removeObjectForKey:(id)key compare:(BOOL(^)(id comparekey))compare;

- (void)addKvPairDirectFromArray:(NSArray *)arPair;

//直接加入到数组
- (void)addKvPairDirect:(XMSKvPair *)kv;

//直接加入到数组
- (void)addKey:(id)key value:(id)value;

- (void)insertKvPair:(XMSKvPair *)kv directAtIndex:(NSUInteger)nIndex;

//compare比较后决定是否加入数组
- (void)addKvPair:(XMSKvPair *)kv;

//比较后决定是否加入数组
- (void)addKvPair:(XMSKvPair *)kv compareKey:(BOOL(^)(id comparekey))compare;

- (void)addKvPairFromOtherQueueDictionary:(XMSQueueDictionary *)qd;

- (void)addKvPairFromOtherQueueDictionary:(XMSQueueDictionary *)qd compareKey:(BOOL(^)(id comparekey1, id comparekey2))compare;

- (void)addKvPairFromOtherQueueDictionaryDirect:(XMSQueueDictionary *)qd;

- (void)addKvPairFromDictionary:(NSDictionary *)dic;

- (NSMutableDictionary *)toNSDictionary;

- (NSUInteger)indexOfKey:(id)key;

- (NSUInteger)indexOfKey:(id)key compareKey:(BOOL(^)(id comparekey))compare;

- (XMSKvPair *)kvPairAtLast;

- (XMSKvPair *)kvPairAtIndex:(NSUInteger)nIndex;

- (XMSKvPair *)kvPairAtKey:(id)key;

- (XMSKvPair *)kvPairAtKey:(id)key compareKey:(BOOL(^)(id comparekey))compare;

- (void)setValue:(id)value atIndex:(NSUInteger)nIndex;

- (void)setValue:(id)value forKey:(id)key;

- (id)keyAtLast;

- (id)valueAtLast;

- (id)getValueForKey:(id)key;

- (id)getValueForIndex:(NSUInteger)nIndex;

- (id)getKeyForIndex:(NSUInteger)nIndex;

- (id)getKeyForCompareKey:(BOOL(^)(id key))compare;

- (id)getValueForKey:(id)key value:(id(^)())value;

- (id)getValueForCompareKey:(BOOL(^)(id key))compare;

- (id)getValueForKey:(id)key compareKey:(BOOL(^)(id key))compare value:(id(^)())value;

- (void)setValue:(id)value forKey:(id)key compareKey:(BOOL(^)(id comparekey))compare;

- (void)setValue:(id(^)())value Key:(id)key compareKey:(BOOL(^)(id comparekey))compare;

- (void)sort:(BOOL)ascending;

- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block;

- (void)enumerateKeyValuesUsingBlock:(void (^)(id key, id value, NSUInteger idx, BOOL *stop))block;

@end

@interface XMSQueueDictionary (NSMutableArrayValue)

//加入一个key，并返回与该key对应的空数组
- (NSMutableArray *)addArrayValueWithkey:(id)key;

- (NSMutableArray *)addArrayValueWithSetKey:(id)key;

//插入一个key，并返回与该key对应的空数组
- (NSMutableArray *)insertArrayValueWithkey:(id)key atIndex:(NSUInteger)nIndex;

/**
 *  枚举所有KeyValuePair中每个value数组的每一个元素
 *
 *  @param block block
 */
- (void)enumerateArrayValueUsingBlock:(void (^)(id key, id obj, NSUInteger idx, BOOL *stop))block;

- (void)enumerateObjectUsingBlockFromBegin:(void (^)(id key, id obj, NSUInteger idx1, NSUInteger idx2, BOOL *stop))block;

- (void)enumerateObjectUsingBlockFromEnd:(void (^)(id key, id obj, NSUInteger idx1, NSUInteger idx2, BOOL *stop))block;

- (NSUInteger)totalCount;

- (id)valueAtKeyArrayIndex:(NSUInteger)nIndex1 valueArrayIndex:(NSUInteger)nIndex2;

- (id)objectAtLast;

- (NSMutableArray*)arrayValueAtIndex:(NSUInteger)nIndex;

- (NSMutableArray*)allArrayValue;

@end
